#ifndef _SNAKE_CONTROLLER_H_
#define _SNAKE_CONTROLLER_H_

#include <ncurses.h>
#include <vector>
#include "snake.h"

// 临时障碍物结构体
struct TemporaryObstacle
{
    SnakeBody position;
    long long creationFrame; // 创建时游戏的总帧数
};

class SnakeController
{
public:
    SnakeController();
    ~SnakeController();
    
    // 控制两条蛇的函数（添加暂停支持）
    int controlSnakesWithPause(Snake* snake1, Snake* snake2, bool& boost1, bool& boost2,
        std::vector<TemporaryObstacle>& temporaryObstacles,
        long long frameCounter, long long& player1LastDropFrame,int SkillCooldownFrames,
        long long& player2LastDropFrame, bool& isPaused, bool isReversed1 = false, bool isReversed2 = false, 
        bool *isSkillActive1 = nullptr, bool *isSkillActive2 = nullptr);
    
    // 获取技能冷却时间常量
    static const int SKILL_COOLDOWN_FRAMES = 1;
    
private:
    // 处理玩家1输入
    bool handlePlayer1Input(int key, Snake* snake1, bool& boost1, 
                           std::vector<TemporaryObstacle>& temporaryObstacles, int skillCooldownFrames,
                           long long frameCounter, long long& player1LastDropFrame, bool &isSkillActive1);
    
    // 处理玩家2输入
    bool handlePlayer2Input(int key, Snake* snake2, bool& boost2, 
                           std::vector<TemporaryObstacle>& temporaryObstacles, int skillCooldownFrames,
                           long long frameCounter, long long& player2LastDropFrame, bool &isSkillActive2);

    bool handlePlayer1InputReversed(int key, Snake* snake1, bool& boost1,
                            std::vector<TemporaryObstacle>& temporaryObstacles, int skillCooldownFrames,
                            long long frameCounter, long long& player1LastDropFrame, bool &isSkillActive1);

    bool handlePlayer2InputReversed(int key, Snake* snake2, bool& boost2,
                            std::vector<TemporaryObstacle>& temporaryObstacles, int skillCooldownFrames,
                            long long frameCounter, long long& player2LastDropFrame, bool &isSkillActive2);
};

#endif